package king.dominic.jlibrary.fragment;

import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
import android.util.Log;

import java.util.ArrayList;
import java.util.Arrays;

import king.dominic.jlibrary.util.PermissionUtil;

/**
 * Created by DominicKing on 2018/1/23.
 * OriginPermissionFragment
 */

public class OriginPermissionFragment extends Fragment implements PermissionUtil.PermissionHandler{
    private ArrayList<PermissionUtil.PermissionItem> permissionUtils;
    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        Log.d("PermissionFragment", "onRequestPermissionsResult: "+ Arrays.toString(grantResults));
        PermissionUtil.permissionRequest(requestCode, permissions, grantResults, permissionUtils);
    }

    @Override
    public void add(PermissionUtil.PermissionItem item) {
        if (permissionUtils == null) permissionUtils = new ArrayList<>();
        permissionUtils.add(item);
    }

    @Override
    public void handlerRequestPermissions(@NonNull String[] permissions, int requestCode) {
        Log.d("PermissionFragment", "handlerRequestPermissions: "+ Arrays.toString(permissions));
        requestPermissions(permissions, requestCode);
    }
}
